package com.leetcode;

/**
 * 883. 三维形体投影面积
 * 优化版本代码
 *
 * @author fy
 * @date 2022/4/26 9:43
 */
public class Solution883_1 {

    public int projectionArea(int[][] grid) {
        int area = 0;
        for (int i = 0; i < grid.length; i++) {
            int yMax = 0;
            int zMax = 0;
            for (int j = 0; j < grid[0].length; j++) {
                area += (grid[j][i] > 0 ? 1 : 0);
                zMax = Math.max(zMax, grid[j][i]);
                yMax = Math.max(yMax, grid[i][j]);
            }
            area += zMax;
            area += yMax;
        }
        return area;
    }

}
